﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Common
{
    public class Cls_ACQCards : BaseNode
    {
        public Cls_ACQCards(XmlNode Node)
            : base(Node)
        {
            if (Node == null)
            {
                throw new XmlException("Node is equal null");
            }
            _XmlNode = Node;
        }

        private List<Cls_ACQCard> _list = null;

        public List<Cls_ACQCard> ACQCards
        {
            get
            {
                Cls_ACQCard c = null;
                if (null != _list)
                    _list.Clear();
                else
                    _list = new List<Cls_ACQCard>();
                foreach (XmlNode x in _XmlNode.SelectNodes("ACQCard"))
                {
                    c = new Cls_ACQCard(x);
                    _list.Add(c);
                }
                _list.Sort();
                return _list;
            }
        }

        public Cls_ACQCard ACQCard(int id)
        {
            XmlNode Acq;
            XmlDocument doc = this._XmlNode.OwnerDocument;

            //add new 
            Acq = _XmlNode.SelectSingleNode("ACQCard[@id=" + id.ToString() + "]");
            if (Acq == null) return null;

            return new Cls_ACQCard(Acq);

        }

    
        //添加时间：2014/8/4
        //添加人：李福安
        //修改时间：
        //修改人：
        public void DeleteCard(int id)
        {
            Cls_ACQCard ch = this.ACQCard(id);
            if (null == ch) return;

            XmlNode n = ch.Node.ParentNode;
            n.RemoveChild(ch.Node);
        }


        //Add 
        //添加时间：2014/8/1
        //添加人：洪伟刚
        //修改时间：2014/8/4
        //修改人：李福安
        public Cls_ACQCard AddACQCard(int id)
        {
            //find 
            XmlNode Acq;
            XmlDocument doc = this._XmlNode.OwnerDocument;
            Cls_ACQCard ExistACQ = ACQCard(id);
            if (null != ExistACQ) return ExistACQ;

            //add new 
            Acq = _XmlNode.AppendChild(doc.CreateElement("ACQCard"));
            Acq.Attributes.Append(doc.CreateAttribute("id")).Value = id.ToString();

            ///采集卡名称
            Acq.AppendChild(doc.CreateElement("Name")).InnerText = "采集卡" + (id+1);
            ///跟踪键相
            Acq.AppendChild(doc.CreateElement("Speed")).InnerText = "";
            ///跟踪键相ID
            Acq.AppendChild(doc.CreateElement("SpeedId")).InnerText = "";
            return new Cls_ACQCard(Acq);
        }
    }

    public class Cls_ACQCard:BaseNode
    {

       // public TcpIpControl MyTcpIpControl = null;

        public Cls_ACQCard(XmlNode Node)
            : base(Node)
        {
            if (Node == null)
            {
                throw new XmlException("Node is equal null");
            }
            _XmlNode = Node;
           // MyTcpIpControl = new TcpIpControl(this);
        }

        public string Speed
        {
            get
            {
                return _XmlNode["Speed"].InnerText;
            }
            set
            {
                XmlDocument doc = _XmlNode.OwnerDocument;
                XmlNode x = _XmlNode["Speed"];
                if (null == x)
                    x = _XmlNode.AppendChild(doc.CreateElement("Speed"));
                _XmlNode["Speed"].InnerText = value.ToString();
            }
        }


        public string SpeedId
        {
            get
            {
                return _XmlNode["SpeedId"].InnerText;
            }
            set
            {
                XmlDocument doc = _XmlNode.OwnerDocument;
                XmlNode x = _XmlNode["SpeedId"];
                if (null == x)
                    x = _XmlNode.AppendChild(doc.CreateElement("SpeedId"));
                _XmlNode["SpeedId"].InnerText = value.ToString();
            }
        }

        public Cls_Channels ChannelList
        {
            get
            {
                //XmlNode x = _XmlNode.SelectSingleNode("ChannelList");
                XmlNode x = _XmlNode.SelectSingleNode("ChannelList");
                if (x == null)
                    x = _XmlNode.AppendChild(_XmlNode.OwnerDocument.CreateElement("ChannelList"));
                return new Cls_Channels(x);
            }
        }
      
    }
}
